#include <iostream>
#include <pthread.h>
#include <unistd.h>

void *routine(void *arg)
{
    int cnt = 5;
    while (cnt--)
    {
        std::cout << "这里新线程, " << (char *)arg << std::endl;
        sleep(1);
    }

    return nullptr;
}

int main()
{
    // 创建子线程
    
    pthread_t tid;
    
    int ret = pthread_create(&tid, nullptr, routine, (void *)"thread - 1");
    if (ret != 0)
    {
        std::cout << "pthread_create error: " << ret << std::endl;
    }

    // 回收子线程
    pthread_join(tid, nullptr);

    return 0;
}